export default {
  data () {
    return {
      noiseEchart: null,
      noiseData: [{value: 10}, {value: 12}, {value: 11}, {value: 11}, {value: 9}, {value: 12}, {value: 10}],
      noiseOption: {
        tooltip: {
          trigger: 'axis',
          confine: true,
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        grid: {
          left: 20,
          right: 20,
          bottom: 0,
          top: 40,
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['1日', '2日', '3日', '4日', '5日', '昨天', '今日'],
            axisLabel: {
              color: '#939393'
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#e8e8e8',
                width: 2
              }
            },
            axisTick: {
              show: false
            },
            splitLine: {
              show: false,
              lineStyle: {
                color: '#a8c5ed'
              }
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: 'dB',
            nameTextStyle: {
              color: '#939393'
            },
            axisLabel: {
              show: true,
              color: '#939393'
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#e8e8e8',
                width: 2
              }
            },
            splitLine: {
              show: false,
              lineStyle: {
                type: 'dashed',
                color: '#e8e8e8'
              }
            },
            position: 'right'
          }
        ],
        series: [{
          name: 'TSP',
          type: 'line',
          areaStyle: {
            color: {
              type: 'linear',
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [{
                offset: 0, color: 'rgba(234, 242, 255, 0.9)' // 0% 处的颜色
              }, {
                offset: 1, color: 'rgba(234, 242, 255, 0.1)' // 100% 处的颜色
              }],
              globalCoord: false // 缺省为 false
            }
          },
          itemStyle: {
            color: '#a3c3fe',
            opacity: 0
          },
          data: []
        }]
      }
    }
  },
  methods: {
    initNoise () {
      if (this.noiseEchart) {
        this.noiseOption.series.forEach(item => {
          item.data = []
        })
      }
      if (this.deviceDustWorkSum.noise) {
        this.noiseOption.xAxis[0].data = this.days
      }
      this.noiseOption.series[0].data = this.deviceDustWorkSum.noise.map((item) => {
        return item.value || 0
      })
      this.noiseEchart = this.$Echarts.init(this.$refs.noise)
      this.noiseEchart.setOption(this.noiseOption)
    }
  }
}
